****
** Replication File:
**
** "The 2020 Presidential Election and Beliefs About Fraud:
** Continuity or Change?"
**
** October 2020
****

set more off

* Install "domin" package
ssc install domin

* Set working directory 

* Open October 2020 data
use "Clean Data, October 2020.dta", version(12) replace

********************************************************************************

****
** Table 1
****	

sum postoffice-cancel

* 41.65; R=44.62, D=44.08
tab voterfraud
tab voterfraud if rep == 1
tab voterfraud if rep == 0

gen voterfraud_dum = 0
replace voterfraud_dum = 1 if voterfraud > 3
prtest voterfraud_dum, by(rep)

* 47.32; R=69.19, D=30.76
tab mailin
tab mailin if rep == 1
tab mailin if rep == 0

gen mailin_dum = 0
replace mailin_dum = 1 if mailin > 3
prtest mailin_dum, by(rep)

* 41.41; R=28.55, D=54.44
tab postoffice
tab postoffice if rep == 1
tab postoffice if rep == 0

gen postoffice_dum = 0
replace postoffice_dum = 1 if postoffice > 3
prtest postoffice_dum, by(rep)

* 48.86; R=22.84, D=71.56
tab leaveoffice
tab leaveoffice if rep == 1
tab leaveoffice if rep == 0

gen leaveoffice_dum = 0
replace leaveoffice_dum = 1 if leaveoffice > 3
prtest leaveoffice_dum, by(rep)

* 12.32; R=10.35, D=14.69
tab cancel
tab cancel if rep == 1
tab cancel if rep == 0

gen cancel_dum = 0
replace cancel_dum = 1 if cancel > 3
prtest cancel_dum, by(rep)

*****
** Standardized coefficients
** for Figure 2
*****	

* Generate standardized variables
foreach v of var pid ideo conthink edu income darktriad ///
	postoffice-cancel age socialmedia female hispanic white black ///
	pidstrength ideostrength anomie denialism rep conserv{ 
	egen `v'st = std(`v')
}

reg voterfraudst conthinkst repst conservst pidstrengthst ideostrengthst ///
	 darktriadst anomiest denialismst socialmediast edust agest incomest ///
	 femalest whitest blackst hispanicst
est store mod1	 
	 
reg mailinst conthinkst repst conservst pidstrengthst ideostrengthst ///
	 darktriadst anomiest denialismst socialmediast edust agest incomest ///
	 femalest whitest blackst hispanicst
est store mod2	 
	 
reg postofficest conthinkst repst conservst pidstrengthst ideostrengthst ///
	 darktriadst anomiest denialismst socialmediast edust agest incomest ///
	 femalest whitest blackst hispanicst
est store mod3	 
	 
reg leaveofficest conthinkst repst conservst pidstrengthst ideostrengthst ///
	 darktriadst anomiest denialismst socialmediast edust agest incomest ///
	 femalest whitest blackst hispanicst
est store mod4	 	 
	 
reg cancelst conthinkst repst conservst pidstrengthst ideostrengthst ///
	 darktriadst anomiest denialismst socialmediast edust agest incomest ///
	 femalest whitest blackst hispanicst	 
est store mod5	 	 
	 
* Save model estimates
estout mod1, cells("b ci_l ci_u")
estout mod2, cells("b ci_l ci_u")
estout mod3, cells("b ci_l ci_u")
estout mod4, cells("b ci_l ci_u")
estout mod5, cells("b ci_l ci_u")

****
** Table A2 and Figure A1 (appendix)
****	

* Recode variables to range from 0–1
foreach v of var pid ideo conthink edu income darktriad ///
	postoffice-cancel facebook twitter instagram reddit narcissism ///
	chans attend interest age socialmedia manipulate ///
	pidstrength ideostrength anomie denialism sociopathy { 
	su `v', meanonly 
	gen `v'2 = (`v' - r(min))/(r(max) - r(min)) 
}

reg voterfraud conthink2 rep conserv pidstrength2 ideostrength2 ///
	 darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	 female white black hispanic
est store mod1	 
margins, at(conthink2=(0(.1)1))
margins, at(rep=(0(1)1))
margins, at(conserv=(0(1)1))
margins, at(pidstrength2=(0(.3333333)1))
margins, at(ideostrength2=(0(.3333333)1))
margins, at(darktriad2=(0(.1)1))
margins, at(anomie2=(0(.1)1))
margins, at(denialism2=(0(.1)1))
margins, at(socialmedia2=(0(.1)1))
	
reg mailin conthink2 rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, beta
est store mod2	
margins, at(conthink2=(0(.1)1))
margins, at(rep=(0(1)1))
margins, at(conserv=(0(1)1))
margins, at(pidstrength2=(0(.3333333)1))
margins, at(ideostrength2=(0(.3333333)1))
margins, at(darktriad2=(0(.1)1))
margins, at(anomie2=(0(.1)1))
margins, at(denialism2=(0(.1)1))
margins, at(socialmedia2=(0(.1)1))

reg postoffice conthink2 rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, beta
est store mod3	
margins, at(conthink2=(0(.1)1))
margins, at(rep=(0(1)1))
margins, at(conserv=(0(1)1))
margins, at(pidstrength2=(0(.3333333)1))
margins, at(ideostrength2=(0(.3333333)1))
margins, at(darktriad2=(0(.1)1))
margins, at(anomie2=(0(.1)1))
margins, at(denialism2=(0(.1)1))
margins, at(socialmedia2=(0(.1)1))

reg leaveoffice conthink2 rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, beta
est store mod5	
margins, at(conthink2=(0(.1)1))
margins, at(rep=(0(1)1))
margins, at(conserv=(0(1)1))
margins, at(pidstrength2=(0(.3333333)1))
margins, at(ideostrength2=(0(.3333333)1))
margins, at(darktriad2=(0(.1)1))
margins, at(anomie2=(0(.1)1))
margins, at(denialism2=(0(.1)1))
margins, at(socialmedia2=(0(.1)1))

reg cancel conthink2 rep conserv pidstrength2 ideostrength2  ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, beta
est store mod4	
margins, at(conthink2=(0(.1)1))
margins, at(rep=(0(1)1))
margins, at(conserv=(0(1)1))
margins, at(pidstrength2=(0(.3333333)1))
margins, at(ideostrength2=(0(.3333333)1))
margins, at(darktriad2=(0(.1)1))
margins, at(anomie2=(0(.1)1))
margins, at(denialism2=(0(.1)1))
margins, at(socialmedia2=(0(.1)1))


estout mod1 mod2 mod3 mod4 mod5, cells(b(star fmt(3)) se(par fmt(3))) ///
   legend label varlabels(_cons constant) stats(r2 N, fmt(3 0 1))	
	
estimates table mod1 mod2 mod3 mod4 mod5, ///
	b(%10.3f) se(%10.3f) stats(r2 N)   

putdocx begin
putdocx table tbl1 = etable, width(100%)
putdocx save regressions.docx, replace	

****
** Table 3
****

domin voterfraud conthink2 rep conserv pidstrength2 ideostrength2 ///
	 darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	 female white black hispanic, epsilon

domin mailin conthink2 rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, epsilon
	
domin postoffice conthink2 rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, epsilon
	
domin leaveoffice conthink2 rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, epsilon
	
domin cancel conthink2 rep conserv pidstrength2 ideostrength2  ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 income2 ///
	female white black hispanic, epsilon

*****
** Table A1 (appendix)
*****

sum age, detail
tab edu
sum female
sum income, detail
tab white
tab black
tab hispanic
	 
*****
** Table A3 (appendix)
*****		 

reg voterfraud conthink2 rep conserv pidstrength2 ideostrength2 ///
	socialmedia2 edu2 age2 income2 female white black hispanic
est store mod1
	
reg mailin conthink2 rep conserv pidstrength2 ideostrength2 ///
	socialmedia2 edu2 age2 income2 female white black hispanic
est store mod2
	
reg postoffice conthink2 rep conserv pidstrength2 ideostrength2 ///
	socialmedia2 edu2 age2 income2 female white black hispanic
est store mod3	
	
reg cancel conthink2 rep conserv pidstrength2 ideostrength2 ///
	socialmedia2 edu2 age2 income2 female white black hispanic
est store mod4

reg leaveoffice conthink2 rep conserv pidstrength2 ideostrength2 ///
	socialmedia2 edu2 age2 income2 female white black hispanic
est store mod5

esttab mod1 mod2 mod3 mod4 mod5 using "Predispositions.rtf", ///
	cells(b(star fmt(3)) se(par fmt(3))) legend label ///
	varlabels(_cons Constant) stats(r2 N, fmt(3 0 1)) ///
	addnotes(Note: OLS coefficients with standard errors in parentheses)
	
*****
** Table A4 (appendix)
*****

reg voterfraud rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 ///
	income2 female white black hispanic
est store mod6
	
reg mailin rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 ///
	income2 female white black hispanic
est store mod7	
	
reg postoffice rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 ///
	income2 female white black hispanic
est store mod8	
	
reg cancel rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 ///
	income2 female white black hispanic
est store mod9
	
reg leaveoffice rep conserv pidstrength2 ideostrength2 ///
	darktriad2 anomie2 denialism2 socialmedia2 edu2 age2 ///
	income2 female white black hispanic
est store mod10	
	
esttab mod6 mod7 mod8 mod9 mod10 using "Psychological Orientations.rtf", ///
	cells(b(star fmt(3)) se(par fmt(3))) legend label ///
	varlabels(_cons Constant) stats(r2 N, fmt(3 0 1)) ///
	addnotes(Note: OLS coefficients with standard errors in parentheses)
	
	
	
	
